package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingprojectMapper;
import com.zzyl.service.NursingprojectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingprojectServiceimpl implements NursingprojectService {
    @Autowired
    private NursingprojectMapper nursingprojectMapper;
    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> nursingProjects = nursingprojectMapper.queryPage(name,status);
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return nursingProjectVoPageResponse;
    }

    @Override
    public int addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setCreateBy(22l);
        nursingProject.setUpdateBy(22l);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        return nursingprojectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo getNursingProject(Long id) {
        NursingProject nursingProject = nursingprojectMapper.getNursingProject(id);
        return BeanUtil.toBean(nursingProject, NursingProjectVo.class);
    }

    @Override
    public int updateNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        return nursingprojectMapper.updateNursingProject(nursingProject);
    }

    @Override
    public int updatestatus(Long id, Integer status) {
        return nursingprojectMapper.updateStatus(id,status);
    }

    @Override
    public int deteleNursingProject(Long id) {
        return nursingprojectMapper.deleteNursingProject(id);
    }

    @Override
    public List<NursingProjectVo> getall() {
        return nursingprojectMapper.getall();
    }
}
